package org.whuims.pois.copy;

import org.joda.time.DateTime;

/**
 * Created by asus on 2014/7/8.
 */
public class test {

    public DateTime StringToDate(String dateStr){
        if (dateStr==null) return null;
        else {
            int timelength = dateStr.split("-| |\\:|\\.").length;
            String[] time = dateStr.split("-| |\\:|\\.");
            int year, month,day;
            DateTime dateTime = null;
            if (dateStr.equals("")||dateStr==null||dateStr.length()==0){
                dateTime = new DateTime();
            }
            if (timelength==3){
                year = Integer.parseInt(time[0]);
                month = Integer.parseInt(time[1]);
                day = Integer.parseInt(time[2]);
                dateTime = new DateTime(year, month, day, 0 , 0, 0);
            }

            if (timelength==4){
                year = Integer.parseInt(time[0]);
                month = Integer.parseInt(time[1]);
                day = Integer.parseInt(time[2]);
                int hour = Integer.parseInt(time[3]);
                dateTime = new DateTime(year, month, day, hour, 0, 0);
            }
            if (timelength==5){
                year = Integer.parseInt(time[0]);
                month = Integer.parseInt(time[1]);
                day = Integer.parseInt(time[2]);
                int hour = Integer.parseInt(time[3]);
                int minute = Integer.parseInt(time[4]);
                dateTime = new DateTime(year, month, day, hour, minute, 0);
            }
            if (timelength>=6){
                year = Integer.parseInt(time[0]);
                month = Integer.parseInt(time[1]);
                day = Integer.parseInt(time[2]);
                int hour = Integer.parseInt(time[3]);
                int minute = Integer.parseInt(time[4]);
                int second = Integer.parseInt(time[5]);
                dateTime = new DateTime(year, month, day, hour, minute, second);
            }
            return dateTime;
        }
    }

    public static void main(String[] args){
        new test().StringToDate(null);
    }
}
